import axios from './ajax';

function get_code_msg_ajax(callback) {
  axios.get("api/User/checkcode", {
    params
  }).then(res => {
    if (res.code == 1) {
      callback(res.msg)
    } else {
      mui.toast("获取失败，请重新获取")
    }
  }).catch(err => {
    mui.toast("服务器错误")
  })
}


function get_code_msg(el, phone_num,callback) {


  var colorEl = el;


  axios.get("api/User/checkcode", {
    params:{
      phone: phone_num
    }
  }).then(res => {
    console.log("获取短信验证码")
    console.log(res)

    if (res) {
      mui.toast("验证码已发送")
      callback(res)
      colorEl.disabled = 'disable';
      colorEl.className = 'classcolor';
      let time = 60;
      let set = setInterval(function () {
        if (time == 0) {
          colorEl.disabled = ''
          colorEl.value = '重新获取'
          colorEl.className = 'login-num-btn';
          clearInterval(set);
        } else {
          time--
          colorEl.value = time
        }
      }, 1000);

    } else {
      mui.toast("获取失败，请重新获取")
    }
  }).catch(err => {
    mui.toast("服务器错误")
  })


  /*
   $.ajax({
     type:"get",
     url:"https://zhapp.4hl.cn/api/User/checkcode",
     data:{
       phone:app.user.phone
     },
     success:function(res){

       console.log(res)
       res = $.trim(res);
       app.server_code = res;
     },
     error:function(){

     }

   });

   */
}


export default {
  get_code_msg
}
